<template>
	<view>

		<view style="border-radius: 10px;background-color: #fff;">
			<navbox title="个人中心"></navbox>
			<view style="margin: 200rpx 0rpx 40rpx 225rpx">
				<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" width="300rpx"
					height="300rpx" :maxCount="1"></u-upload>
			</view>
			<view style="margin-left: 20rpx;margin-right: 20rpx;">
				<u-collapse @change="change" @close="close" @open="open" :value="['Docs']">
					<u-collapse-item title="基本信息" name="Docs">
						<view class="view1">
							<u-icon color="#ffecb9" slot="icon" size="32" name="calendar"></u-icon>
							<view class="view2">用户名:</view>
							<u--input placeholder="请输入内容" v-model="user.nickName" border="bottom" clearable></u--input>
						</view>
						<view v-if="user.frentLink!==5&&user!==''">
							<view class="view1">
								<u-icon color="#ffcbd7" slot="icon" size="32" name="calendar"></u-icon>
								<view class="view2">手机号:</view>
								<u--input placeholder="请输入内容" v-model="user.phone" border="bottom" clearable></u--input>
							</view>
							<view class="view1">
								<u-icon color="#ffffae" slot="icon" size="32" name="calendar"></u-icon>
								<view class="view2">邮箱:</view>
								<u--input placeholder="请输入内容" v-model="user.email" border="bottom" clearable></u--input>
							</view>
							<view class="view1">
								<u-icon color="#acb9ff" slot="icon" size="32" name="calendar"></u-icon>
								<view class="view2">生日:</view>
								<u--input placeholder="请输入内容" v-model="user.birth" border="bottom" clearable></u--input>
							</view>
						</view>

						<view class="view1">
							<u-icon color="#beffaf" slot="icon" size="32" name="calendar"></u-icon>
							<view class="view2">个性签:</view>
							<u--input placeholder="请输入内容" v-model="user.userTab" border="bottom" clearable></u--input>
						</view>
						<view class="view1">
							<u-icon color="#ceacff" slot="icon" size="32" name="calendar"></u-icon>
							<view class="view2">密码:</view>
							<u--input placeholder="请输入内容" password v-model="user.passWord" border="bottom" clearable>
							</u--input>
						</view>
					</u-collapse-item>
					<u-collapse-item title="更多" name="Docs guide">
						<view class="view1">
							<u-icon color="#ceacff" slot="icon" size="32" name="calendar"></u-icon>
							<view class="view2" style="width: 100%;">您童年的绰号叫什末？</view>
						</view>
						<u--input placeholder="请输入内容" password v-model="wen.wen1" border="bottom" clearable>
						</u--input>
						<view class="view1">
							<u-icon color="#ceacff" slot="icon" size="32" name="calendar"></u-icon>
							<view class="view2" style="width: 100%;">不能说的秘密？</view>
						</view>
						<u--input placeholder="请输入内容" password v-model="wen.wen2" border="bottom" clearable>
						</u--input>
						<view class="view1">
							<u-icon color="#ceacff" slot="icon" size="32" name="calendar"></u-icon>
							<view class="view2" style="width: 100%;">不能忘记的事情？</view>
						</view>
						<u--input placeholder="请输入内容" password v-model="wen.wen3" border="bottom" clearable>
						</u--input>
						<view style="width: 100%;height: 35rpx;"></view>
						<u-button type="primary" text="确定" @click="wendaupdate()"></u-button>
					</u-collapse-item>
				</u-collapse>
			</view>
			<u-tabbar :value="value1" @change="change1" :fixed="true" :placeholder="false" :safeAreaInsetBottom="false">
				<u-tabbar-item text="首页" icon="home" @click="click1"></u-tabbar-item>
				<u-tabbar-item text="个人中心" icon="man-delete" @click="click1"></u-tabbar-item>
				<u-tabbar-item text="保存" icon="edit-pen" @click="click1"></u-tabbar-item>
			</u-tabbar>

		</view>

	</view>
</template>

<script>
	import navbox from '../components/navbox/navbox.vue'
	export default {
		data() {
			return {
				user: uni.getStorageSync("user"),
				fileList1: [
		 
					],
				value1: 1,
				wen: {
					wen1: '',
					wen2: '',
					wen3: '',
					userId: uni.getStorageSync("user").id
				}

			}
		},
		onLoad() {
		},
		methods: {
			async wendaupdate() {
				const res2 = await this.$myRuquest({
					url: '/wexinLogin/wenvo',
					method: 'post',
					data: this.wen
				})
				uni.showToast({
					title: "修改成功",
					icon: 'none'
				})
			},
			async click1(e) {
				if (e === 0) {
					uni.switchTab({
						url: '/pages/index/index'
					})
				} else if (e === 2) {
					const res2 = await this.$myRuquest({
						url: '/wexinLogin/updateUser',
						method: 'post',
						data: this.user
					})
					uni.setStorageSync("user", this.user)
					uni.switchTab({
						url: '/pages/index/index'
					})
					uni.showToast({
						title: res2.data.data !== true ? "修改失败" : "修改成功",
						icon: 'none'
					})
				}
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$baseurl + '/wexinLogin/pictures/uploadAvator?userId=' + this.user.id,
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							const da = JSON.parse(res.data)
							this.user.picUrl = da.data
							console.log(this.user)
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},

			open(e) {
				// console.log('open', e)
			},
			close(e) {
				// console.log('close', e)
			},
			change(e) {
				// console.log('change', e)
			},
			change1(name) {
				this.value1 = name
			},
		},
		components: {
			"navbox": navbox
		},
	}
</script>

<style>
	.view1 {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		height: 95rpx;
	}

	.view2 {
		margin-left: 10rpx;
		margin-left: 10rpx;
		width: 100rpx;
	}
</style>
